import getpath
import requests
import os
import logging
import myglobal
from urllib.parse import urlparse
check_path_short="dist"
check_path=os.path.join(getpath.getpath(),check_path_short)
hth=None
def download_one(one):
    (name,url)=one
    logging.info(url)
    path = urlparse(url).path  # 获取路径部分: /limsdoc/report/5/2/1045-2025.06.06.11.36-1749180986677.zip
    file_name =myglobal.make_valid_filename(name)+"__"+path.split("/")[-1]  # 取最后一个 / 后的内容
    save_path =os.path.join(check_path, file_name)
    # 禁用 SSL 验证（仅用于内网/可信来源）
    response = myglobal.global_session.get(url, verify=False)  
    if response.status_code == 200:
        with open(save_path, "wb") as f:
            f.write(response.content)
        logging.info(f"文件已下载到: {save_path}")
    else:
        logging.info(f"下载失败，HTTP 状态码: {response.status_code}")
def download_path(url):
    rpt_host = "http://10.0.114.213:8805/limsdoc/report/"
    if url[0] == "/":
        url = url[1:]
    name="fn"
    download_one((name,rpt_host + url))